//
//  CrossCell.m
//  糗事百科
//
//  Created by 奚超明 on 16/6/1.
//  Copyright © 2016年 奚超明. All rights reserved.
//

#import "CrossCell.h"
#import "CrossModel.h"
#import "CrossUserModel.h"
#import "ImageModel.h"

@interface CrossCell ()
@property (weak, nonatomic) IBOutlet UIImageView *iconImageView;
@property (weak, nonatomic) IBOutlet UILabel *nameLabel;
@property (weak, nonatomic) IBOutlet UILabel *contentLabel;
@property (weak, nonatomic) IBOutlet UILabel *likeLabel;
@property (weak, nonatomic) IBOutlet UILabel *commentLabel;
@property (weak, nonatomic) IBOutlet UILabel *shareLabel;
/** 图片 */
@property (nonatomic, strong) UIImageView *contentImageView;

@end

@implementation CrossCell

- (void)awakeFromNib {
    [super awakeFromNib];
    
    self.iconImageView.layer.cornerRadius = self.iconImageView.xcm_width * 0.5;
    self.iconImageView.layer.masksToBounds = YES;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

}

- (void)setModel:(CrossModel *)model
{
    _model = model;
    [self.iconImageView sd_setImageWithURL:[NSURL URLWithString:model.user.icon]];
    self.nameLabel.text = model.user.login;
    self.contentLabel.text = model.content;
    self.likeLabel.text = [NSString stringWithFormat:@"好笑 %@", [model.up stringValue]];
    self.commentLabel.text = [NSString stringWithFormat:@"评论 %@", [model.comments_count stringValue]];
    self.shareLabel.text = [NSString stringWithFormat:@"分享 %@", [model.share_count stringValue]];
    
    if (model.image) {
        CGFloat imageViewWidth = model.image_size.width;
        CGFloat imageViewHeight = model.image_size.height;
        CGFloat imageViewX = kMargin;
        CGFloat imageViewY = model.cellHeight - kBottomHeight - 2 * kMargin - imageViewHeight;
        self.contentImageView.frame = CGRectMake(imageViewX, imageViewY, imageViewWidth, imageViewHeight);
        [self.contentImageView sd_setImageWithURL:[NSURL URLWithString:model.image]];
        self.contentImageView.hidden = NO;
    } else {
        self.contentImageView.hidden = YES;
    }
}

- (void)setFrame:(CGRect)frame
{
    frame.size.height -= kMargin;
    [super setFrame:frame];
}

- (UIImageView *)contentImageView
{
    if (!_contentImageView) {
        _contentImageView = [[UIImageView alloc] init];
        [self.contentView addSubview:self.contentImageView];
    }
    return _contentImageView;
}

@end
